home *** CD-ROM | disk | FTP | other *** search
/ Amiga News 95 / Amiga News 95.iso / dpat / dpat62 / cliexchange_1.4 / cliexchange.c < prev    next >
C/C++ Source or Header  |  1994-02-20  |  4KB  |  141 lines

  1. /*
  2.    NAME
  3.         CLIExchange
  4.  
  5.    FUNCTION
  6.         replacement command for the Exchange utility
  7.  
  8.    INPUTS
  9.         cxlist  - list of commodity names
  10.         command - switch associated with a message of type CXM_COMMAND
  11.  
  12.    RESULT
  13.         success/failure indicator
  14.  
  15.    REQUIREMENTS
  16.         dos.library V36+
  17.         commodities.library V36+
  18.  
  19.    AUTHORS
  20.         written by Gael Marziou and Reza Elghazi
  21.  
  22.    HISTORY
  23.         +---------+----------+---------+--------------------------+
  24.         | version | creation | size in | comment                  |
  25.         | number  | date     | bytes   |                          |
  26.         +---------+----------+---------+--------------------------+
  27.         | 1.0     | 15/01/94 | 688     | very first release       |
  28.         | 1.1     | 19/01/94 | 672     |                          |
  29.         | 1.2     | 20/01/94 | 592     |                          |
  30.         | 1.3     | 28/01/94 | 504     | added missing FreeArgs() |
  31.         | 1.4     | 04/02/94 | 584     | added INFO switch        |
  32.         +---------+----------+---------+--------------------------+
  33. */
  34.  
  35. #include <string.h>
  36.  
  37. #include <clib/alib_protos.h>
  38. #include <clib/commodities_protos.h>
  39. #include <clib/dos_protos.h>
  40. #include <clib/exec_protos.h>
  41.  
  42. #include <pragmas/commodities_pragmas.h>
  43. #include <pragmas/dos_pragmas.h>
  44. #include <pragmas/exec_pragmas.h>
  45.  
  46. #define TEMPLATE "CXNAME/M,DISABLE/S,ENABLE/S,APPEAR/S,DISAPPEAR/S,KILL/S,UNIQUE/S,INFO/S"
  47.  
  48. #define OPT_CXNAME    0
  49. #define OPT_DISABLE   1
  50. #define OPT_ENABLE    2
  51. #define OPT_APPEAR    3
  52. #define OPT_DISAPPEAR 4
  53. #define OPT_KILL      5
  54. #define OPT_UNIQUE    6
  55. #define OPT_INFO      7
  56.  
  57. #define OPT_COUNT     8
  58.  
  59. /*****************************************************************/
  60. /* The following definitions have been found in the MUI-Exchange */
  61. /* source code (written by Klaus Melchior)                       */
  62. /*****************************************************************/
  63.  
  64. /***  commodities.library private functions  ***/
  65. #pragma libcall CxBase CopyBrokerList ba 801
  66. #pragma libcall CxBase FreeBrokerList c0 801
  67. #pragma libcall CxBase BrokerCommand  c6 802
  68.  
  69. LONG CopyBrokerList(struct List *);
  70. LONG FreeBrokerList(struct List *);
  71. LONG BrokerCommand(BYTE *,LONG);
  72.  
  73. /*** private structures ***/
  74. struct BrokerCopy {
  75.     struct Node bc_Node;
  76.     char        bc_Name[CBD_NAMELEN];
  77.     char        bc_Title[CBD_TITLELEN];
  78.     char        bc_Descr[CBD_DESCRLEN];
  79.     LONG        bc_Task;
  80.     LONG        bc_Dummy1;
  81.     LONG        bc_Dummy2;
  82.     UWORD       bc_Flags;
  83. };
  84.  
  85. LONG
  86. CLIExchange (VOID)
  87. {
  88.     struct DosLibrary *DOSBase;
  89.     struct Library    *CxBase;
  90.     struct RDArgs     *rdargs;
  91.     struct Node       *n,*nn;
  92.     struct List       l;
  93.     LONG   i,cmd,opts[OPT_COUNT],rc = RETURN_FAIL;
  94.     UBYTE  *name,*title,*descr,**argptr,
  95.            *version = "$VER:CLIExchange 1.4 (4.2.94)";
  96.  
  97.     /* before bothering with anything else, open the libraries we need */
  98.     DOSBase = (struct DosLibrary *)OpenLibrary("dos.library",36L);
  99.     CxBase  = OpenLibrary("commodities.library",36L);
  100.  
  101.     if (DOSBase && CxBase) {
  102.         memset(opts,NULL,sizeof(opts));
  103.  
  104.         /* parse the command line */
  105.         if (rdargs = ReadArgs(TEMPLATE,opts,NULL)) {
  106.             /* find out which option the user has set */
  107.             for (i=OPT_DISABLE; !opts[i] && i<OPT_INFO; i++);
  108.             if (i<OPT_INFO) cmd = CXCMD_DISABLE+2*i-2;
  109.  
  110.             NewList(&l);
  111.             CopyBrokerList(&l);
  112.  
  113.             for (n = l.lh_Head; n && (nn = n->ln_Succ); n = nn) {
  114.                 name = ((struct BrokerCopy *)n)->bc_Name;
  115.  
  116.                 if (opts[OPT_CXNAME]) {
  117.                     for (argptr = (BYTE **)opts[OPT_CXNAME]; *argptr && strcmp(*argptr,name); *argptr++);
  118.                     if (!*argptr) continue;
  119.                 }
  120.  
  121.                 if (opts[OPT_INFO]) {
  122.                     title = ((struct BrokerCopy *)n)->bc_Title;
  123.                     descr = ((struct BrokerCopy *)n)->bc_Descr;
  124.  
  125.                     Printf("%-39s:%s\n",title,descr);
  126.                 }
  127.                 else if (i != OPT_INFO) BrokerCommand(name,cmd);
  128.                 else if (!opts[OPT_CXNAME]) Printf("%s\n",name);
  129.             }
  130.  
  131.             FreeBrokerList(&l);
  132.             FreeArgs(rdargs);
  133.             rc = RETURN_OK;
  134.         }
  135.         else PrintFault(IoErr(),NULL);
  136.     }
  137.     CloseLibrary(CxBase);
  138.     CloseLibrary((struct Library *)DOSBase);
  139.     return(rc);
  140. }
  141.